#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int number = nums[0];
        int count = 1;
        for (int i = 1; i < nums.size(); i++) {
            if (nums[i] == number) {
                count++;
            } else {
                if (count == 1) {
                    count = 1;
                    number = nums[i];
                } else {
                    count--;
                }
            }
        }
        return number;
    }
};


int main() {
    vector<int> input = {2, 2, 1, 1, 1, 2, 2};
    Solution solution;
    int output = solution.majorityElement(input);
    cout << output << endl;
    return 0;
}
